<?php

include_once "EventHandler.php";
include_once "xhtml_lib/XHTML_Td.php";
include_once "xhtml_lib/XHTML_Tr.php";
include_once "xhtml_lib/XHTML_Table.php";
include_once "xhtml_lib/XHTML_Form.php";
include_once "xhtml_lib/XHTML_Select.php";
include_once "xhtml_lib/XHTML_Input.php";
include_once "xhtml_lib/XHTML_Option.php";
include_once "GestorDptos.php";
include_once "Dpto.php";

class IUDptos extends XHTML_Form implements EventHandler {

	private $listaDptos;
	
	private $btnCrear;
	
	private $btnEliminar;
	
	private $btnCancelar;
	
	private $gestorDptos;
	
	function __construct()
	{
		parent::__construct("");
		$celda1 = new XHTML_Td();
		$celda2 = new XHTML_Td();
		$fila1 = new XHTML_Tr($celda1);
		$fila1->addCell($celda2);
		$tabla1 = new XHTML_Table($fila1);
		$tabla1->setBorder(1);
		$this->addElement($tabla1);
		
		$this->listaDptos = new XHTML_Select();
		$this->listaDptos->setSize(6);
		$this->listaDptos->setTabIndex(1);
		$celda1->addElement($this->listaDptos);
		
		$celda2_1 = new XHTML_Td();
		$celda2_2 = new XHTML_Td();
		$celda2_3 = new XHTML_Td();
		$fila2_1 = new XHTML_Tr($celda2_1);
		$fila2_2 = new XHTML_Tr($celda2_2);
		$fila2_3 = new XHTML_Tr($celda2_3);
		
		$tabla2_1 = new XHTML_Table($fila2_1);
		$tabla2_1->addBodyElement($fila2_2);
		$tabla2_1->addBodyElement($fila2_3);
		$celda2->addElement($tabla2_1);
		
		$this->btnCrear = new XHTML_Input();
		$this->btnCrear->setType("button");
		$this->btnCrear->setValue("Crear");
		$this->btnCrear->setTabIndex(2);
		$celda2_1->addElement($this->btnCrear);
		$this->btnCrear->setOnClick("javascript:makeRequest('Application.php', '?_sender_=btnCrear&_event_=onClick', 'contenido');");
		
        $this->btnEliminar = new XHTML_Input();
        $this->btnEliminar->setType("button");
        $this->btnEliminar->setValue("Eliminar");
		$this->btnEliminar->setTabIndex(3);
		$celda2_2->addElement($this->btnEliminar);
		
        $this->btnCancelar = new XHTML_Input();
        $this->btnCancelar->setType("button");
        $this->btnCancelar->setValue("Cancelar");
		$this->btnCancelar->setTabIndex(4);
		$celda2_3->addElement($this->btnCancelar);
		
		$this->gestorDptos = new GestorDptos();
		$this->actualizar();
	}
	
	function actualizar()
	{
	    $listado = $this->gestorDptos->obtenerListaDptos();
	    if (count($listado) > 0) {
	        foreach ($listado as $dpto) {
    	        $option = new XHTML_Option();
	            $option->setText($dpto->getNombre());
	            $this->listaDptos->addElement($option);
	        }
	    }
	}
	
	function handleEvent($sender, $event)
	{
	    switch ($sender) {
	        case "btnCrear": {
	            switch($event) {
	                case "onClick": {
	                    include "prueba.php";
	                }
	            }
	        }; break;
	    }
	}
	
	function mostrar()
	{
	    //$_SESSION["application"]->set
	    echo $this->toString();
	}

}

?>